#if 0

#include <iostream>
#include <string>
#include <sstream>
#include <stdlib.h>
#include <fstream>

#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;

const int N = 10240;

void Test(void) {
	char line[N];
	FILE *fp;
	string cmd = "sudo lsof";
	////引号内是你的linux指令
	// 系统调用
	const char *sysCommand = cmd.data();
	if ((fp = popen(sysCommand, "r")) == NULL) {
		cout << "error" << endl;
		return;
	}
	while (fgets(line, sizeof(line) - 1, fp) != NULL) {
		cout << line;
	}
	pclose(fp);
}

bool srvPortIsUsed(int port)
{
	//std::stringstream srm;
	std::stringstream ss;
	ss << "sudo lsof -i:" << port << " > netstat.txt";
	std::string str = ss.str();
	//srm << "lsof -i :" << port << " >netstat.txt";
	system(str.c_str());
	std::ifstream _in("srvPortIsUsed.txt", std::ifstream::in);
	std::string line;
	std::getline(_in, line);
	std::getline(_in, line);
	if (!line.empty())
	{
		//line.find_first_of(' ');
		//line = line.substr(line.find_first_of(' ') + 1);
		//line = line.substr(0, line.find_first_of(' '));
		//std::string sr = "kill -9 " + line;
		//system(sr.c_str());
		std::cout << "Port: " << port << " in used" << std::endl;
		return true;
	}
	else {
		std::cout << "Port: " << port << " not in used" << std::endl;
		return false;
	}
		


}

int main(int argc, char *argv[])
{	
	printf("%d\n", argc);
	printf("%s\n", argv[0]);
	printf("%s\n", argv[1]);
	//printf("%s\n", argv[2]);
	srvPortIsUsed(atoi(argv[1]));
	getchar();
	Test();
	getchar();
	return 0;
}

#endif // 0